package org.electronic.registration.bo;

import javax.persistence.*;

/**
 * User: Egor
 * Date: 17.12.11
 */
@Entity(name = "Arm.Patient")
@Table(name = "Arm.Patient")
@NamedQueries({
        @NamedQuery(name = Patient.GET_ALL_PATIENTS, query = "select d from Arm.Patient d"),
        @NamedQuery(name = Patient.GET_PATIENT_BY_EMAIL, query = "select p from Arm.Patient p where p.email= ?"),
        @NamedQuery(name = Patient.GET_PATIENT_BY_NAME, query = "select p from Arm.Patient p where p.fullName like ?")
})
public class Patient {

    public static final String GET_ALL_PATIENTS = "GET_ALL_PATIENTS";
    public static final String GET_PATIENT_BY_EMAIL = "GET_PATIENT_BY_EMAIL";
    public static final String GET_PATIENT_BY_NAME = "GET_PATIENT_BY_NAME";


    @Id
    @GeneratedValue
    private Integer id;

    private String fullName;

    private String email;

    private String login;

    private String password;
    @ManyToOne(targetEntity = Region.class)
    @JoinColumn(name = "region")
    private Region region;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }


    public Region getRegion() {
        return region;
    }

    public void setRegion(Region region) {
        this.region = region;
    }


    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Patient patient = (Patient) o;

        if (email != null ? !email.equals(patient.email) : patient.email != null) return false;
        if (fullName != null ? !fullName.equals(patient.fullName) : patient.fullName != null) return false;
        if (id != null ? !id.equals(patient.id) : patient.id != null) return false;
        if (login != null ? !login.equals(patient.login) : patient.login != null) return false;
        if (password != null ? !password.equals(patient.password) : patient.password != null) return false;
        if (region != null ? !region.equals(patient.region) : patient.region != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (fullName != null ? fullName.hashCode() : 0);
        result = 31 * result + (email != null ? email.hashCode() : 0);
        result = 31 * result + (login != null ? login.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (region != null ? region.hashCode() : 0);
        return result;
    }
}
